package com.yy.try_;

/**
 * chapter12  com.yy.try_
 * 2023-05-10 09:20
 *
 * @author yy yuyue
 * description : 不可描述
 * @date 2023/5/10 9:20
 */
public class TryCatchExercise02 {
}


class Exception02{

    public static int method(){
        int i = 1;
        try {
            i++;//i = 2
            String[] names = new String[3];//String[] 数组
            if(names[1].equals("tom")){// NullPointerException  空指针
                System.out.println(names[1]);
            }else {
                names[3] = "yy";
            }
            return 1;
        }catch (ArrayIndexOutOfBoundsException e){
            return 2;
        }catch (NullPointerException e){//捕获
            return ++i;// i = 3    int tmp = ++i;
        }finally {//必须执行
            return ++i;//i = 4
        }
    }

    public static void main(String[] args) {
        System.out.println(method());
    }
}